home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 446_01 / DOC / SPLINES / EX / PROG4.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-18  |  1.1 KB  |  36 lines

  1. // *********************** Prog4.C ***********************
  2. // A program which shows the usage of TPSurface
  3. #include <TPSurface.h>
  4. #include <splineOutput.h>
  5.  
  6. int main()
  7. {
  8.   const real Pi =  M_PI;  // M_PI is defined in math.h
  9.   // surface data to be interpolated:
  10.   Vec(real) gridlines(9); gridlines.fill(-4.0/3.0, 4.0/3.0);
  11.   ArrayGenSimple(real) funcval(9,9);
  12.   for (int i = 1; i <= 9; i++)
  13.     for (int j = 1; j <= 9; j++) funcval(i,j)= sin(gridlines(i)*gridlines(j));
  14.  
  15.   KnotVec k(7);  // knot vector for the parameters (same for both parameters)
  16.   k.fill(-sqrt(Pi),sqrt(Pi));  k.regulate(4);
  17.   SplineSpace space(k,4);  // cubic spline
  18.  
  19.   TPSurface spline_surface;
  20.   spline_surface.redim(space,space);  // same grid in both directions
  21.   spline_surface.interpolation(gridlines,gridlines,funcval);
  22.  
  23.   // evaluate the spline function on a lattice for later plotting of the
  24.   // fitted surface:
  25.   Vec(real) newgridlines(41);
  26.   newgridlines.fill(-1.5,1.5);  // lattice coordinates
  27.  
  28.   createPlotmtvFile(spline_surface,newgridlines,newgridlines,
  29.                     "FILE=surface.mtv");
  30.   return 0;
  31. }
  32.  
  33.  
  34.  
  35.  
  36.